using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;

namespace M13.Utility.Registrar
{
    /// <summary>
    /// ��Ƥע����
    /// </summary>
    /// <typeparam name="t"></typeparam>
    public class TurfRegistrar<t> where t : Turf, new()
    {
        public static t Registered(byte turfId, string turfName, Material turfMaterial, Dictionary<byte, Turf> intDatas, Dictionary<string, Turf> strDatas)
        {
            Type myType = typeof(t);
            t myInstance = Activator.CreateInstance(myType) as t;
            MethodInfo methodInfo = myType.GetMethod("TurfInit", BindingFlags.NonPublic | BindingFlags.Instance);
            object[] myParaeters = new object[] { turfId, turfName, turfMaterial };
            if (myInstance != null)
                methodInfo.Invoke(myInstance, myParaeters);
            intDatas.Add(turfId, myInstance);
            strDatas.Add(turfName, myInstance);
            return myInstance;
        }
    }
}